<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-3.4.1.min.js"></script>
    <link rel="stylesheet" href="/css/bootstrap.min.css">


    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="/plugins/bootstraptable/bootstrap-table.min.css">
</head>
<body>
<div class="bgc1">
    <div class="updatebox">
        <h2>修改密码</h2>
        <hr>
        <form id="form">
            <div class="form-group">
                <label for="userName1">姓名</label>
                <input type="text" class="form-control" id="userName1" placeholder="请输入姓名" name="userName1">
            </div>
            <div class="form-group">
                <label for="oldpassword">原密码</label>
                <input type="password" class="form-control" id="oldpassword" placeholder="请输入原密码" name="oldpassword">
            </div>
            <div class="form-group">
                <label for="newpassword">新密码</label>
                <input type="password" class="form-control" id="newpassword" placeholder="请输入新密码" name="newpassword">
            </div>
            <div class="form-group">
                <label for="confirmpassword">确认密码</label>
                <input type="password" class="form-control" id="confirmpassword" placeholder="请确认密码" name="confirmpassword">
            </div>

            <button type="button" class="btn btn-primary btn1" onclick="updatePass();">修改</button>
        </form>
    </div>
</div>

<script src="/js/jquery-3.4.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/plugins/bootstraptable/bootstrap-table.min.js"></script>
<script src="/plugins/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="/js/msg.js"></script>

<script>
    function updatePass(){
        let newpassword = $("#newpassword").val()
        let confirmpassword = $("#confirmpassword").val()
        if (!newpassword){
            message.showText("error","密码不得为空");
        }else if (newpassword !== confirmpassword){
            message.showText("error","两次密码输入不一致");
        }else {
            $.ajax({
                url: "/webapi/update/password",
                method: "post",
                data:{
                    userName: $("#userName1").val(),
                    oldpassword: $("#oldpassword").val(),
                    newpassword: $("#newpassword").val()
                }
            }).done(function (rs){
                if (rs.code === 200){
                    message.showText("success",rs.msg)
                    $("#userName1").val("")
                    $("#oldpassword").val("")
                    $("#newpassword").val("")
                    $("#confirmpassword").val("")
                }else if (rs.code === 500){
                    message.showText("error",rs.msg)
                }else if (rs.code === 400){
                    message.showText("error",rs.msg)
                }
            })
        }

    }
</script>
</body>
</html>